﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EHTSaleManager.Code.BLL;
using EHTSaleManager.Code.Entity;
using EHTSaleManager.Code.Utility;
using System.Data;
using System.IO;
using System.Net;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;


namespace EHTSaleManager.UIAdmin
{
    public partial class AdminFAQ : System.Web.UI.Page
    {
        private Int32 ID = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                try
                {
                    ID = Int32.Parse(Request.QueryString["ID"].ToString());
                }
                catch (Exception ex)
                {
                    ID = -1;
                }

                if (ID == -1)
                {
                    ViewState["action"] = HangSo.ACTION_ADD;

                }
                else
                {
                    FAQs theFAQs = FAQsProvider.GetFAQsbyID(ID);

                    if (theFAQs == null)
                        Response.Redirect("AdminFAQs.aspx");
                    else
                    {
                        this.txtTitleFAQs.Text = theFAQs.TitleFAQs;
                        FCKContent.Value = theFAQs.ContentFAQs;
                        this.ddlFAQs.SelectedValue = theFAQs.Type.ToString();
                        ViewState["ID"] = theFAQs.ID;
                        ViewState["action"] = HangSo.ACTION_UPDATE;
                    }
                }
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminFAQs.aspx");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
             String action = ViewState["action"].ToString();

            FAQs theFAQs = new FAQs();
            theFAQs.TitleFAQs = this.txtTitleFAQs.Text.Trim();
            theFAQs.ContentFAQs = FCKContent.Value.ToString().Trim();
            theFAQs.Type = Int32.Parse(ddlFAQs.SelectedValue.ToString().Trim());
           
            if (action == HangSo.ACTION_ADD)
            {
                theFAQs.ID = -1;
                FAQsProvider.IUFAQs(theFAQs, true);
            }
            else
            {
                theFAQs.ID = Int32.Parse(ViewState["ID"].ToString());
                FAQsProvider.IUFAQs(theFAQs, false);
            }

           Response.Redirect("AdminFAQs.aspx");
        
        }
    }
}